package moxl.relaxng.validation.testsuite.testsuitetests;

import moxl.dom.MoxlElement;
import moxl.dom.raw.RawBackedElement;
import moxl.parser.ParserException;
import moxl.parser.XmlParser;
import moxl.parser.resource.ClassResourceStreamXmlResource;
import moxl.raw.XmlResourceException;
import moxl.relaxng.validation.testsuite.TheJamesClarkUnofficialTestSuiteTest;
import moxl.tokenizer.TokenizerException;

import org.junit.internal.runners.CompositeRunner;
import org.junit.internal.runners.InitializationError;

public class RelaxNgSuiteTestRunner extends CompositeRunner
{
	public RelaxNgSuiteTestRunner(Class<?> klass) throws InitializationError, TokenizerException, XmlResourceException, ParserException
	{
		super("Root");
		System.out.println("Created with class: " + klass.getName());
		ClassResourceStreamXmlResource testResource = new ClassResourceStreamXmlResource(TheJamesClarkUnofficialTestSuiteTest.class,
		        "distribution/spectest.xml");
		XmlParser parser = new XmlParser();
		MoxlElement doc = new RawBackedElement(parser.parse(testResource));

		for (MoxlElement el : doc.getChildElements())
		{
			if (el.getLocalName().equals("testSuite"))
			{
				RelaxNgTestObject suite = new RelaxNgTestSuite(el);
				suite.contributeTests(this, klass);
			}
			else if (el.getLocalName().equals("testCase"))
			{
				throw new UnsupportedOperationException("TODO: name is " + el.getLocalName());
			}
		}
	}


}
